/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Nuevo.java
 *
 * Created on 11/06/2011, 09:15:22 AM
 */

package aplicacion;

import javax.swing.JOptionPane;

/**
 *
 * @author diego
 */
public class Nuevo extends javax.swing.JDialog {

    /** Creates new form Nuevo */
    public Nuevo(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroupSexo = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jTextFieldNombres = new javax.swing.JTextField();
        jTextFieldDNI = new javax.swing.JTextField();
        jTextFieldApPaterno = new javax.swing.JTextField();
        jTextFieldApMaterno = new javax.swing.JTextField();
        jRadioButtonHombre = new javax.swing.JRadioButton();
        jRadioButtonMujer = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jButtonGuardar = new javax.swing.JButton();
        jButtonCancelar = new javax.swing.JButton();
        jComboBoxTablas = new javax.swing.JComboBox();
        jLabel6 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel1.setMaximumSize(new java.awt.Dimension(370, 241));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jTextFieldNombres.setFont(new java.awt.Font("Arial", 0, 11));
        jPanel1.add(jTextFieldNombres, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 137, 230, 20));

        jTextFieldDNI.setFont(new java.awt.Font("Arial", 0, 11));
        jPanel1.add(jTextFieldDNI, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 47, 230, 20));

        jTextFieldApPaterno.setFont(new java.awt.Font("Arial", 0, 11));
        jPanel1.add(jTextFieldApPaterno, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 77, 230, 20));

        jTextFieldApMaterno.setFont(new java.awt.Font("Arial", 0, 11));
        jPanel1.add(jTextFieldApMaterno, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 110, 230, 20));

        buttonGroupSexo.add(jRadioButtonHombre);
        jRadioButtonHombre.setSelected(true);
        jRadioButtonHombre.setText("Hombre");
        jPanel1.add(jRadioButtonHombre, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 170, -1, -1));

        buttonGroupSexo.add(jRadioButtonMujer);
        jRadioButtonMujer.setText("Mujer");
        jPanel1.add(jRadioButtonMujer, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 170, -1, -1));

        jLabel1.setText("Sexo :");
        jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 170, -1, -1));

        jLabel2.setText("Tabla :");
        jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 20, -1, -1));

        jLabel3.setText("Apellido Paterno :");
        jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 80, -1, -1));

        jLabel4.setText("Apellido Materno :");
        jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 110, -1, -1));

        jLabel5.setText(" Nombres :");
        jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 140, -1, -1));

        jButtonGuardar.setText("Guardar");
        jButtonGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonGuardarActionPerformed(evt);
            }
        });
        jPanel1.add(jButtonGuardar, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 210, -1, -1));

        jButtonCancelar.setText("Cancelar");
        jButtonCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancelarActionPerformed(evt);
            }
        });
        jPanel1.add(jButtonCancelar, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 210, -1, -1));

        jComboBoxTablas.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Todos", "MOVISTAR CABLEMAGICO", "MOVISTAR TELEFONO", "MOVISTAR INTERNET" }));
        jPanel1.add(jComboBoxTablas, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 17, 230, 20));

        jLabel6.setText("DNI :");
        jPanel1.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 50, -1, -1));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 400, 260));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonGuardarActionPerformed

         if(jTextFieldDNI.getText().trim().length() == 0)
         {
             JOptionPane.showMessageDialog(this, "El campo DNI no debe ser nulo o vacio");
         }
         else
         {  
             ConexionMySQL con = new ConexionMySQL();
             int sexo = buttonGroupSexo.getButtonCount()-1;
             con.abrirConexion();
             switch (jComboBoxTablas.getSelectedIndex())
             {
                 case 0:
                        con.insertarTablas("MOVISTAR_CABLEMAGICO","" ,  " VALUES ('"+jTextFieldDNI.getText().trim()+"', '"+jTextFieldNombres.getText().trim()+"', '"+jTextFieldApPaterno.getText().trim()+"', '"+jTextFieldApMaterno.getText().trim()+"', "+sexo+")", "");
                        con.insertarTablas("MOVISTAR_INTERNET"   ,"" ,  " VALUES ('"+jTextFieldDNI.getText().trim()+"', '"+jTextFieldNombres.getText().trim()+"', '"+jTextFieldApPaterno.getText().trim()+"', '"+jTextFieldApMaterno.getText().trim()+"', "+sexo+")", "");
                        con.insertarTablas("MOVISTAR_TELEFONO"   ,"" ,  " VALUES ('"+jTextFieldDNI.getText().trim()+"', '"+jTextFieldNombres.getText().trim()+"', '"+jTextFieldApPaterno.getText().trim()+"', '"+jTextFieldApMaterno.getText().trim()+"', "+sexo+")", "");
                    break;
                 case 1:
                        con.insertarTablas("MOVISTAR_CABLEMAGICO","" ,  " VALUES ('"+jTextFieldDNI.getText().trim()+"', '"+jTextFieldNombres.getText().trim()+"', '"+jTextFieldApPaterno.getText().trim()+"', '"+jTextFieldApMaterno.getText().trim()+"', "+sexo+")", "");
                    break;
                 case 2:
                        con.insertarTablas("MOVISTAR_TELEFONO"   ,"" ,  " VALUES ('"+jTextFieldDNI.getText().trim()+"', '"+jTextFieldNombres.getText().trim()+"', '"+jTextFieldApPaterno.getText().trim()+"', '"+jTextFieldApMaterno.getText().trim()+"', "+sexo+")", "");
                     break;
                 case 3:
                        con.insertarTablas("MOVISTAR_INTERNET"   ,"" ,  " VALUES ('"+jTextFieldDNI.getText().trim()+"', '"+jTextFieldNombres.getText().trim()+"', '"+jTextFieldApPaterno.getText().trim()+"', '"+jTextFieldApMaterno.getText().trim()+"', "+sexo+")", "");
                    break;
             }
             
         }
         
        // TODO add your handling code here:
    }//GEN-LAST:event_jButtonGuardarActionPerformed

    private void jButtonCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancelarActionPerformed
        
        // TODO add your handling code here:
    }//GEN-LAST:event_jButtonCancelarActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                Nuevo dialog = new Nuevo(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroupSexo;
    private javax.swing.JButton jButtonCancelar;
    private javax.swing.JButton jButtonGuardar;
    private javax.swing.JComboBox jComboBoxTablas;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JRadioButton jRadioButtonHombre;
    private javax.swing.JRadioButton jRadioButtonMujer;
    private javax.swing.JTextField jTextFieldApMaterno;
    private javax.swing.JTextField jTextFieldApPaterno;
    private javax.swing.JTextField jTextFieldDNI;
    private javax.swing.JTextField jTextFieldNombres;
    // End of variables declaration//GEN-END:variables

}
